﻿using Dapper.IService;
using Dapper.Model;
using Microsoft.Extensions.Configuration;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Dapper.Service
{
    public class TestService:ITestService
    {
        //IConfiguration _configuration;
        //public TestService(IConfiguration configuration)
        //{
        //    _configuration = configuration;
        //}
        //public IDbConnection GetConnection()
        //{
        //    var connectionString = _configuration.GetSection("ConnectionString").GetSection("mysqlServer").Value;
        //    var conn = new MySqlConnection(connectionString);
        //    return conn;
        //}


        IConfiguration _configuration;
        MySqlConnection conn;
        public TestService(IConfiguration configuration)
        {
            _configuration = configuration;
            var connectionString = _configuration.GetSection("ConnectionString").GetSection("mysqlServer").Value;
            conn = new MySqlConnection(connectionString);
        }


        public User GetById(string Id)
        {
            object[] param = new object[]
                {
                    "@userId",Id
                };
            return conn.QuerySingle<User>("select * from User where userId=@userId", param);
        }
    }
}
